#include"../logs/bitlog.h"
#include<unistd.h>


void test_log(const std::string &name)
{
    INFO("%s","测试开始");
    bitlog::Logger::ptr logger=bitlog::LoggerManager::getInstance().getLogger("async_logger");
    logger->debug("%s","测试日志");
    logger->info("%s","测试日志");
    logger->warn("%s","测试日志");
    logger->error("%s","测试日志");
    logger->fatal("%s","测试日志");
    size_t count=0;

    INFO("%s","测试完毕");

}

int main()
{


    std::unique_ptr<bitlog::LoggerBuilder>builder(new bitlog::GlobalLoggerBuilder());
    builder->buildLoggerName("async_logger");
    builder->buildLoggerLevel(bitlog::LogLevel::value::DEBUG);
    builder->buildFormatter("[%c][%f:%l][%p]%m%n");
    builder->buildLoggerType(bitlog::LoggerType::LOGGER_SYNC);
    builder->buildSink<bitlog::FileSink>("./logfile/sync.log");
    builder->buildSink<bitlog::StdoutSink>();
    builder->buildSink<bitlog::RollBySizeSink>("./logfile/roll-sync.log-by-size",1024*1024);
    builder->build();
    test_log("async_logger");

    // logger->debug(__FILE__,__LINE__,"%s","测试日志");
    // logger->info(__FILE__,__LINE__,"%s","测试日志");
    // logger->warn(__FILE__,__LINE__,"%s","测试日志");
    // logger->error(__FILE__,__LINE__,"%s","测试日志");
    // logger->fatal(__FILE__,__LINE__,"%s","测试日志");
    // size_t count=0;
    // while(count<500000)
    // {
    //     logger->fatal(__FILE__,__LINE__,"测试日志-%d",count++);
    // }

//     bitlog::LogMsg msg(bitlog::LogLevel::value::INFO,53,"main.c","root","格式化功能测试...");
//     bitlog::Formatter fmt;
//     std::string str =fmt.format(msg);//格式化
//    bitlog::LogSink::ptr stdout_lsp =bitlog::SinkFactory::create<bitlog::StdoutSink>();
//     bitlog::LogSink::ptr file_lsp =bitlog::SinkFactory::create<bitlog::FileSink>("./logfile/test.log");
//     bitlog::LogSink::ptr roll_lsp =bitlog::SinkFactory::create<bitlog::RollBySizeSink>("./logfile/roll-",1024*1024);
//     stdout_lsp->log(str.c_str(),str.size());
//     file_lsp->log(str.c_str(),str.size());
//     size_t cursize=0;
//     size_t count=0;
//     while(cursize<1024*1024*10)
//     {
//         std::string tmp =str + std::to_string(count++);
//         roll_lsp->log(tmp.c_str(),tmp.size());
//         cursize +=str.size();
//     }


    // std::cout<<bitlog::LogLevel::toString(bitlog::LogLevel::value::DEBUG)<<std::endl;
    // std::cout<<bitlog::LogLevel::toString(bitlog::LogLevel::value::INFO)<<std::endl;
    // std::cout<<bitlog::LogLevel::toString(bitlog::LogLevel::value::WARN)<<std::endl;
    // std::cout<<bitlog::LogLevel::toString(bitlog::LogLevel::value::ERROR)<<std::endl;
    // std::cout<<bitlog::LogLevel::toString(bitlog::LogLevel::value::OFF)<<std::endl;

    // std::cout<<bitlog::util::Date::now()<<std::endl;
    // std::string pathname= "./abc/bcd/a.txt";
    // bitlog::util::File::createDirectory(bitlog::util::File::path(pathname));
    return 0;
}
